//2009/07/25 14:19:12
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Birthday
{
public:
    string getNext(string date, vector <string> birthdays)
    {
		stable_sort(birthdays.begin(), birthdays.end());
		//string s(birthdays[0].substr(0,4));
		for(int i=0; i<birthdays.size(); i++)
		{
			if(date.compare(birthdays[i].substr(0,5)) <= 0)
				return birthdays[i].substr(0,5);
		}
		return birthdays[0].substr(0,5);
    }
};
